package get.newsdaily;


import get.newsdaily.adapters.PaperAdapter;
import get.newsdaily.utils.variables;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.Toast;

public class PaperActivity extends ListActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // setContentView(R.layout.paper); bỏ
        

        /*if (savedInstanceState == null) {
            getSupportFragmentManager().beginTransaction()
                    .add(R.id.container, new PlaceholderFragment())
                    .commit();
        }
        */
        PaperAdapter adapter = new PaperAdapter(this, R.id.tvPaper, variables.PAPERS);
		setListAdapter(adapter);
    }

    
    
    	
    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
    	try{
		super.onListItemClick(l, v, position, id);
		
		Intent intent = new Intent(PaperActivity.this, CategoryActivity.class);
		intent.putExtra(variables.PAPER,position); // position biểu thị vị trí tên trang báo
		
		startActivity(intent); 
    	} catch(Exception e){
        	Toast.makeText(v.getContext(),"Lỗi" + e,Toast.LENGTH_LONG).show(); 
    		Log.w("lỗi khởi động", e.toString());
    	}

    }
    
		
	


	@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.paper, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    /**
     * A placeholder fragment containing a simple view.
     */
    public static class PlaceholderFragment extends Fragment {

        public PlaceholderFragment() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_paper, container, false);
            return rootView;
        }
    }

}
